<?php

    header("Content-Type:text/html;charset=utf-8");

    //链接数据库
 
    
    $conn;
    include '../public/conn.php';
     session_start();
    // 表单数据的获取

    // 标题
    $title = $_POST['logTitle'];
    // 内容
    $content = $_POST['logContent'];
    // 知识单元
    $order = $_POST['logUnit'];     
    // 作者id
    $strName=$_SESSION['userName'];
    $log_id = $_POST['log_id'];
    //插入图片
    $bool = ($_FILES["file"]["type"] == "image/gif"|| $_FILES["file"]["type"] == "image/pjpeg")&& ($_FILES["file"]["size"] < 10000000);
   if (!$bool )
     { echo "类型不对，大小不对";

     }
    if ($_FILES["file"]["error"] > 0){
          echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file:" . ($_FILES["file"]["tmp_name"]) . "<br />";
    if (file_exists("../log/photo/" . $_FILES["file"]["name"])){
        echo $_FILES["file"]["name"] . " already exists. ";
        echo "<img src=\"../log/photo/" . $_FILES["file"]["name"]."\" />";
        }
    else{
         move_uploaded_file($_FILES["file"]["tmp_name"],"../log/photo/" . $_FILES["file"]["name"]);
         echo "上传成功" . "../log/photo/" . $_FILES["file"]["name"];
        echo "<img src=\"../log/photo/" . $_FILES["file"]["name"]."\" />";
          }
    $urlPhoto= "../log/photo/" . $_FILES["file"]["name"]."";

    $sql = mysql_query("UPDATE log SET photo = '$urlPhoto'  WHERE log_id = $log_id", $conn);
                
    $sr = mysql_query($sql);
  
    echo "<script>";
        echo "alert('发表成功！');";
        echo "window.location='student.php';";
        echo "</script>";
 
?>